//
//  OrderItemCell.swift
//  todoios
//
//  Created by qianli on 2025/4/21.
//

import Foundation

class OrderItemCell: UITableViewCell {
    private var bPBMrzl1IFQw0nsq: UILabel = UILabel()
    private var AnZIcpuRZdYPcqgr: UILabel = UILabel()
    private var C0EbSjdlsdaGq5oU: UILabel = UILabel()
    private var SB2ym8bkCyXLybZZ: UILabel = UILabel()
    private var wN32kosskVmE9Hvv: UILabel = UILabel()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .clear
        GHL4Rhb91XYBer27()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func GHL4Rhb91XYBer27(){
        let rowHeight = 110.0
        let conentHeight = 100.0
        let iLeft = 15.0
        let rowView = UIView(frame: CGRect(x: iLeft, y: rowHeight/2-conentHeight/2, width: qianli_pm_width-30, height: conentHeight))
        self.contentView.addSubview(rowView)
        rowView.backgroundColor = .systemBackground
        rowView.layer.cornerRadius = 10
        
        self.bPBMrzl1IFQw0nsq.frame = CGRectMake(iLeft, 10, rowView.bounds.size.width - 2*iLeft, 20)
        rowView.addSubview(self.bPBMrzl1IFQw0nsq)
        self.bPBMrzl1IFQw0nsq.textColor =  .secondaryLabel
        self.bPBMrzl1IFQw0nsq.font = .systemFont(ofSize: 14)
        self.bPBMrzl1IFQw0nsq.text = "订单号 -------"
        
        self.AnZIcpuRZdYPcqgr.frame = CGRectMake(iLeft, 10+20, qianli_pm_width/2, 30)
        rowView.addSubview(self.AnZIcpuRZdYPcqgr)
        self.AnZIcpuRZdYPcqgr.textColor =  .label
        self.AnZIcpuRZdYPcqgr.font = .systemFont(ofSize: 16)
        self.AnZIcpuRZdYPcqgr.text = "-----"
        
        self.C0EbSjdlsdaGq5oU = UILabel(frame: CGRectMake(iLeft, 10+20+30, qianli_pm_width/2, 20))
        rowView.addSubview(self.C0EbSjdlsdaGq5oU)
        self.C0EbSjdlsdaGq5oU.textColor =  .label
        self.C0EbSjdlsdaGq5oU.font = .systemFont(ofSize: 14)
        self.C0EbSjdlsdaGq5oU.text = "xxxx-xx-xx xx:xx:xx"
        
        self.SB2ym8bkCyXLybZZ.frame = CGRectMake(rowView.bounds.size.width-15-80, self.AnZIcpuRZdYPcqgr.frame.minY-5, 80, 20)
        rowView.addSubview(self.SB2ym8bkCyXLybZZ)
        self.SB2ym8bkCyXLybZZ.textColor =  .secondaryLabel
        self.SB2ym8bkCyXLybZZ.font = .systemFont(ofSize: 16)
        self.SB2ym8bkCyXLybZZ.text = "￥--"
        self.SB2ym8bkCyXLybZZ.textAlignment = .center
        
        self.wN32kosskVmE9Hvv.frame = CGRectMake(rowView.bounds.size.width-15-80, self.C0EbSjdlsdaGq5oU.frame.minY-5, 80, 24)
        rowView.addSubview(self.wN32kosskVmE9Hvv)
        self.wN32kosskVmE9Hvv.textColor =  .secondaryLabel
        self.wN32kosskVmE9Hvv.font = .systemFont(ofSize: 12)
        self.wN32kosskVmE9Hvv.text = "交易关闭"
        self.wN32kosskVmE9Hvv.textAlignment = .center
        self.wN32kosskVmE9Hvv.backgroundColor = .systemGray.withAlphaComponent(0.25)
        self.wN32kosskVmE9Hvv.layer.cornerRadius = 24/2
        self.wN32kosskVmE9Hvv.clipsToBounds = true
    }
    
    func Qianli_UpdateInfo(info:OrdersModel){
        self.bPBMrzl1IFQw0nsq.text = "订单号 "+info.out_trade_no
        self.AnZIcpuRZdYPcqgr.text = info.subject
        let iso8601String = info.created_at
        self.C0EbSjdlsdaGq5oU.text = isoDate2Formatdate(iso8601String)
        self.SB2ym8bkCyXLybZZ.text = "￥"+info.total_amount
        Av8WpvN5q7yjJjMe(info.trade_status)
    }
    
    func Av8WpvN5q7yjJjMe(_ status:String){
        self.wN32kosskVmE9Hvv.textColor = .secondaryLabel
        self.wN32kosskVmE9Hvv.backgroundColor = .systemGray.withAlphaComponent(0.25)
        switch status {
        case "WAIT_BUYER_PAY":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Wait Pay") // "等待付款"
            self.wN32kosskVmE9Hvv.textColor = .orange
            self.wN32kosskVmE9Hvv.backgroundColor = .orange.withAlphaComponent(0.25)
        case "TRADE_CLOSED":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Timeout") //"超时关闭"
        case "TRADE_SUCCESS":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Successful") //"交易成功"
            self.wN32kosskVmE9Hvv.textColor = .systemGreen
            self.wN32kosskVmE9Hvv.backgroundColor = .systemGreen.withAlphaComponent(0.25)
        case "TRADE_FINISHED":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Completed") //"交易结束"
        case "COMPLETED":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Manual") //"手动完成"
            self.wN32kosskVmE9Hvv.textColor = .systemGreen
            self.wN32kosskVmE9Hvv.backgroundColor = .systemGreen.withAlphaComponent(0.25)
        case "CREATED":
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Created") //"订单已创建"
            self.wN32kosskVmE9Hvv.textColor = .systemGreen
            self.wN32kosskVmE9Hvv.backgroundColor = .systemGreen.withAlphaComponent(0.25)
        default:
            self.wN32kosskVmE9Hvv.text =  LocalizedString("Unknown") //"未知状态"
        }
    }
}
